import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.TreeSelectionModel;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;

@ScriptManifest(authors={"joku.rules"}, keywords={"Development"}, name="Interface Explorer", version=0.3D, description="Fetches various interface data for developers.")
public class InterfaceExplorer extends Script
  implements PaintListener
{
  private JFrame window;
  private JTree tree;
  private InterfaceExplorer.InterfaceTreeModel treeModel;
  private JPanel infoArea;
  private JTextField searchBox;
  private Rectangle highlightArea = null;

  public int loop()
  {
    if (this.window.isVisible()) {
      return 1000;
    }
    return -1;
  }

  public void onRepaint(Graphics paramGraphics) {
    if (this.highlightArea != null) {
      paramGraphics.setColor(Color.ORANGE);
      paramGraphics.drawRect(this.highlightArea.x, this.highlightArea.y, this.highlightArea.width, this.highlightArea.height);
    }
  }

  public boolean onStart()
  {
    this.window = new JFrame("Interface Explorer");

    this.treeModel = new InterfaceExplorer.InterfaceTreeModel(this, null);
    this.treeModel.update("");
    this.tree = new JTree(this.treeModel);
    this.tree.setRootVisible(false);
    this.tree.setEditable(false);
    this.tree.getSelectionModel().setSelectionMode(1);

    this.tree.addTreeSelectionListener(new InterfaceExplorer.1(this));

    JScrollPane localJScrollPane = new JScrollPane(this.tree);
    localJScrollPane.setPreferredSize(new Dimension(250, 500));
    this.window.add(localJScrollPane, "West");

    this.infoArea = new JPanel();
    this.infoArea.setLayout(new BoxLayout(this.infoArea, 1));
    localJScrollPane = new JScrollPane(this.infoArea);
    localJScrollPane.setPreferredSize(new Dimension(250, 500));
    this.window.add(localJScrollPane, "Center");

    InterfaceExplorer.2 local2 = new InterfaceExplorer.2(this);

    JPanel localJPanel = new JPanel();
    localJPanel.setLayout(new FlowLayout(0));
    localJPanel.add(new JLabel("Filter:"));

    this.searchBox = new JTextField(20);
    this.searchBox.addActionListener(local2);
    localJPanel.add(this.searchBox);

    JButton localJButton = new JButton("Update");
    localJButton.addActionListener(local2);
    localJPanel.add(localJButton);
    this.window.add(localJPanel, "North");

    this.window.pack();
    this.window.setVisible(true);
    return true;
  }
}